const path = require("path");
const fs = require("fs");
const proxy = {
  "/api": {
    target: "http://127.0.0.1:300",
    secure: true,
    changeOrigin: true,
    bypass: function(req, res) {
      if (req.path.indexOf("/payment") == 0 && globalConfig.mockProxy) {
        if (mockObj.json.length > 0) {
          mockObj.json.map(function(item) {
            if (req.path.indexOf(item.name) != -1) {
              var responseMsg = fs.readFileSync(item.path, "utf8");
              console.log("localApi:" + item.name);
              res.send(responseMsg);
            }
          });
        }
      }
    }
  }
};

module.exports = {
  publicPath: "",
  outputDir: "../static/",
  assetsDir: "static",
  // 配置了sentry 监控，必须打开，才能上传sourceMap
  productionSourceMap: true,
  configureWebpack: config => {},
  chainWebpack: config => {
    // 设置svg
    const svgRule = config.module.rule("svg");
    svgRule.uses.clear();
    svgRule
      .use("svg-sprite-loader")
      .loader("svg-sprite-loader")
      .options({
        symbolId: "icon-[name]"
      });
  },
  devServer: {
    contentBase: path.resolve(__dirname, "public"),
    port: 301,
    // liveReload: false,
    // host: 'localhost',
    overlay: {
      warnings: true,
      errors: true
    },
    proxy
  }
};
